#pragma once

#ifndef FACTORY_CONTROL_SYSTEM_AGENT_H
#define FACTORY_CONTROL_SYSTEM_AGENT_H

#include <string>
#include <vector>
#include <list>
#include <QtGui/QMainWindow>
#include "FactoryControlSystem.h"
#include "Agent.h"
#include "KitRecipe.h"

class Agent;
class Kit;
class KitInterface;
class KitRecipe;
class FactoryControlSystemAgent;
class Conveyor;
struct FCSKit;
enum KitProgressStatus;

/**
 * @class	FactoryControlSystemAgent
 *
 * @brief	Factory control system agent.
 *
 * @author	Anoop Kamboj
 */

class FactoryControlSystemAgent : public FactoryControlSystem, public Agent
{
public:

	FactoryControlSystemAgent(std::string);
	~FactoryControlSystemAgent();

	//=====================
	/*	Group: Messages */
	//=====================

	virtual void msgHereIsKitOrder(KitRecipe*);
	//virtual void msgHereIsKitOrder(KitInterface *, int);

	virtual void msgHereIsFinishedKit(KitInterface *);

	// Scheduler

	virtual bool pickAndExecuteAnAction();

	// Getters
	std::vector<FCSKit*>* getKits() const;
	
	std::list<KitRecipe*>* getKitRecipes() const;

	// Setters
	void setConveyor(Conveyor*);
	void setMainWindow(QMainWindow*);

	// Data

	enum KitProgressStatus
	{
		NEW,
		BEING_WORKED_ON,
		FINISHED
	};

protected:

	virtual std::string toString() const;

	//============================
	/*	Actions					*/
	//============================

	void sendKitToKittingCell (KitRecipe*);
	virtual void handleBreak();
	virtual void handleFix();
	
private:

	Conveyor *conveyor;

	//Data
	std::vector<FCSKit*> *kits;
	std::list<KitRecipe*> *kitRecipes;
	Lock kitsListLock;

	QMainWindow *mainWindow;

	//============================
	/*	Utility					*/
	//============================
	
	FCSKit* findKitByStatus (KitProgressStatus);

};

struct FCSKit
{
public:
	KitInterface *kit;
	int amountOrdered;
	FactoryControlSystemAgent::KitProgressStatus state;
		
	FCSKit(KitInterface *k, int amount)
	{
		kit = k;
		amountOrdered = amount;
		state = FactoryControlSystemAgent::FINISHED;//KitProgressStatus::NEW;//FactoryControlSystemAgent::KitProgressStatus::NEW;
	}
};

#endif